
cc.Class({
    extends: cc.Component,

    properties: {
        Fy_NodeHall:cc.Node,
        content:cc.Node,
        Wa_Title:cc.Label,
        Works:cc.Prefab,
        Wa_Tips:cc.Label
    },
    onReturn(){
        this.node.active = false;
        this.Fy_NodeHall.active = true;
    },
    oninof(event,type){
        this.Fy_NodeHall.active = false;
        this.node.active = true;
        if(type == "true"){
            this.Wa_Title.string = "我的作品";   
            this.onMyWork();
        }else{
            this.Wa_Title.string = "我的回答";
            this.onMyAnswer();
        }
    },
    onMyWork(){  //我的作品
      this.onPostRank(true);
    },
    onMyAnswer(){//我的回答
      this.onPostRank(false);
    },
    onPostRank(type){
        this.content.removeAllChildren(true);
        var canshu = type == true ? UserData.MyWork:UserData.MyAnswer;
        var line = 0;
        if(canshu){
            this.Wa_Tips.string = "正在加载中...";
            for(var i = 0; i<canshu.length;i++){
                var RankItem = cc.instantiate(this.Works);
                RankItem.getComponent("Works").init(i,canshu[i]);
                if(i%2 == 0){
                    line = i == 0? 0 : Math.ceil(i/2);
                    RankItem.y = -200-370*line;
                    RankItem.x = -170; 
                    this.content.addChild(RankItem);
                }else{
                    RankItem.y = -200-370*line;
                    RankItem.x = 170; 
                    this.content.addChild(RankItem);
                }
                if(i>2){
                    this.content.height = Math.abs(-200-370*line-200);
                }
            }
            this.Wa_Tips.node.active = false;
        }else{
            this.Wa_Tips.node.active = true;
            type == true ? this.Wa_Tips.string = "暂无作品赶快去发布自家的发言吧":this.Wa_Tips.string = "暂无评论赶快去评论优秀方言吧";
        }
    }
});
